﻿//using System;
//using System.Data;
//using System.Configuration;
//using System.Collections;
//using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;
//using Indeco.G24.Entities;
//using Indeco.G24.Data;
//using Indeco.G24.Services;


//namespace Indeco.G24.Web
//{
//    public class G24Pages : System.Web.UI.Page
//    {
//        public G24Pages()
//        { }
//    }
//}
using System;
using System.Web;
using System.Web.UI;
using System.Diagnostics;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;

//using Business;
//using DMS.DataService;

namespace Indeco.G24.Web
{
    /// <summary>
    /// Summary description for G24Page
    /// </summary>
    public class G24Page : System.Web.UI.Page
    {
        private const string SESSION_KEY_LANGUAGE = "CURRENT_LANGUAGE";
        ///<summary>
		/// G24Page() instance.
		///</summary>
        public G24Page()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new System.EventHandler(this.G24Page_Load);
            this.Error += new System.EventHandler(this.G24Page_Error);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="currentError"></param>
        public static void ShowError(Exception currentError)
        {
            HttpContext context = HttpContext.Current;
            if (currentError.Message.Contains("ORA-02291"))
            {
                context.Response.Write(
                "<link rel=\"stylesheet\" href=\"/Webpages/Styles/Blue.CSS\">" +
                "<h2>Lỗi</h2><hr/>Dữ liệu bạn chọn để cập nhật đã bị xóa.<hr/>");
                return;
            }
            context.Response.Write(
                "<link rel=\"stylesheet\" href=\"/Webpages/Styles/Blue.CSS\">" +
                "<h2>Lỗi</h2><hr/>Một lỗi đã xuất hiện trên trang này. Hệ thống đã " +
                "thông báo lỗi này cho quản trị hệ thống." +
                "<br/><b>Lỗi xuất hiện trong: </b>" +
                "<pre>" + context.Request.Url.ToString() + "</pre><br/>" +
                "<br/><b>Thông Báo Lỗi: </b>" +
                "<pre>" + currentError.Message.ToString() + "</pre><hr/>" +
                "<br/><b>Stack Trace(Truy vết):</b><br/>" +
                "<pre>" + currentError.ToString() + "</pre>");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void G24Page_Error(object sender, System.EventArgs e)
        {
            string errMsg;
            Exception currentError = Server.GetLastError();

            errMsg = "<link rel=\"stylesheet\" href=\"/Webpages/Styles/Blue.CSS\">";
            errMsg += "<h1>Thông Báo Lỗi</h1><hr/>Một lỗi đã xuất hiện trên trang này. Hệ thống đã " +
                "thông báo lỗi về cho quản trị. Đừng ngại thông báo với chúng tôi " +
                "về lỗi này.<br/>" +
                "Lỗi xãy ra ở: " + Request.Url.ToString() + "<br/>" +
                "Thông Báo Lỗi: <font class=\"ErrorMessage\">" + currentError.Message.ToString() + "</font><hr/>" +
                "<b>Stack Trace(Truy Vết):</b><br/>" +
                currentError.ToString();

            if (!(currentError is AppException))
            {
                // It is not one of ours, so we cannot guarantee that it has been logged
                // into the event log.
                AppException.LogError(currentError.Message.ToString());
            }
            // Show error on the page
            ShowError(currentError);
            Server.ClearError();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void G24Page_Load(object sender, System.EventArgs e)
        {
            // For session timeout
            if (Session["G24SessionId"] == null)
            {
                Response.Redirect("TimeOutPage.aspx");
            }
            // TODO: Place any code that will take place BEFORE the Page_Load event
            // in the regular page, e.g. cache management, authentication verification,
            // etc.											
            if (Context.User.Identity.IsAuthenticated)
            {
                //if (!(Context.User is G24Principal))
                {
                    // ASP.NET's regular forms authentication picked up our cookie, but we
                    // haven't replaced the default context user with our own. Let's do that
                    // now. We know that the previous context.user.identity.name is the e-mail
                    // address (because we forced it to be as such in the login.aspx page)				
                    // G24Principal newUser = new G24Principal(Context.User.Identity.Name);
                    // Context.User = newUser;
                }
            }
        }
        /// <summary>
        /// Ham khoi tao
        /// InitializeCulture() 
        /// </summary>
        protected override void InitializeCulture()
        {
            //retrieve culture information from session
            string culture = Convert.ToString(Session[Global.SESSION_KEY_CULTURE]);

            //check whether a culture is stored in the session
            if (culture.Length > 0) Culture = culture;

            //set culture to current thread
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

            //call base class
            base.InitializeCulture();
        }
    }
}